<template>
  <div id="app">
    <router-view/>
  </div>
</template>

<script>

export default{
  name:'app',
  methods:{
    getUser(){
      this.axios.get('/user').then((res={})=>{
        this.$store.dispatch('saveUserName',res.username)
      })
    },
    getCartCount(){
      this.axios.get('/carts/products/sum').then((res=0)=>{
        this.$store.dispatch('saveCartCount',res)
      })
    }
  },
  mounted(){
    //非登陆状态没必要去获取用户id和购物车数量
    if(this.$cookie.get('userId')){
      this.getUser();
      this.getCartCount();
    }
  }
}

</script>

<style lang="scss">

</style>
